<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/19
 * Time: 23:23
 */

namespace Admin\Controller;

class VideoController extends BaseController
{

    public function add_video()
    {
        $this->display();
    }

    public function doAddVideo()
    {
        $info = uploadVideo('video');
        $data['url'] = $info['video_url']['savename'];
        $data['add_time'] = time();
        foreach ($data as $k=>$v) {
            if ($v == '' || $v == null)
                echo "<script>alert('{$k},不能为空');location.replace(document.referrer);</script>";
        }

        $res = M('video')->data($data)->add();

        if ($res) {
            echo "<script>alert('添加成功');location.replace(document.referrer);</script>";
        } else {
            echo "<script>alert('添加失败');location.replace(document.referrer);</script>";
        }
    }

    public function video_list()
    {
        $list = M('video')->order(array('sort'=>'asc','add_time'=>'desc'))->select();

        $this->assign('list',$list);
        $this->display();
    }

    public function updateVideoState()
    {
        $maps['id'] = I('id');

        $data['state'] = I('state');

        $res = M('video')->data($data)->where($maps)->save();
        if ($res) {
            echo "<script>alert('添加成功');location.replace(document.referrer);</script>";
        } else {
            echo "<script>alert('添加失败');location.replace(document.referrer);</script>";
        }
    }

}